# -*- coding: utf-8 -*-

from yyets import VideoFormat, YYETS

import argparse


def parse_cli_args():
    parser = argparse.ArgumentParser(description="parse yyets resource file")
    parser.add_argument(
        "-f",
        "--file",
        required=True,
        help="a yyets reource file",
    )
    parser.add_argument(
        "-vf",
        "--format",
        required=False,
        default=VideoFormat.V_IDONTCARE,
        type=VideoFormat,
        help="video format, eg:"
        + ",".join([x.value for x in VideoFormat if x != VideoFormat.V_IDONTCARE]),
    )
    parser.add_argument(
        "-s",
        "--season",
        default=0,  # all
        type=int,
        help="which season do you want",
    )
    parser.add_argument(
        "-e",
        "--episode",
        default=0,  # all
        type=int,
        help="which episode do you want",
    )
    parser.add_argument(
        "-o",
        "--output",
        help="write result to file",
    )
    parser.add_argument(
        "-i",
        "--info",
        help="only return resource data",
    )

    return parser.parse_args()


if __name__ == "__main__":
    args = parse_cli_args()
    yy = YYETS(args.file)
    yy.get_all_season_no()
    print(yy.get_all_support_formats())
    # print(
    #     [
    #         e.get_url(WayFormat.W_IDONTCARE)
    #         for e in yy.get_all_episodes(1, VideoFormat.V_IDONTCARE)
    #     ]
    # )
    print(yy.get_one_episode(args.format, 1, 1).get_name())
